const { LinValidator, Rule } =  require('@root/core/lin-validator-v2')

class RegisterValidator extends LinValidator {
    constructor() {
        super()
        this.phone = [
            new Rule('isMobilePhone', '手机格式不正确', ['zh-CN'])
        ]
        this.password = [
            new Rule('isLength', '密码最少6个字符，最多32个字符', {
                min: 6,
                max: 32
            }),
            new Rule('matches', '密码格式不符合规范', '(?![0-9]+$)(?![a-zA-Z]+$)[0-9a-zA-Z]')
        ]
        this.confirmPassword = this.password
        this.nickName = [
            new Rule('isLength', '昵称长度不符合规范',{
                min: 2,
                max: 32
            })
        ]
    }
    async validatePassword(vals) {
       const pwd1 = vals.body.password
       const pwd2 = vals.body.confirmPassword
       if(pwd1 !== pwd2) {
           throw new Error('两个密码不一致')
       }
    }
}

module.exports = {
    RegisterValidator
}